package com.cen.cloud.controller;

import com.cen.cloud.pojo.Dept;
import com.cen.cloud.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author cen
 * @Date 2020/10/4 16:29
 */
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    @Autowired
    private DiscoveryClient client;

    @GetMapping("/dept/get")
    public List<Dept> getAll(){
        return deptService.getAll();
    }

    @GetMapping("/dept/getByID/{id}")
    public Dept getByID(@PathVariable("id") Long deptno){
        Dept byID = deptService.getByID(deptno);
        return byID;
    }

    @PostMapping("/dept/add")
    public boolean addDept(Dept dept){
        return deptService.addDept(dept);
    }

    public Object discovery(){
        List<String> services = client.getServices();
        services.forEach(System.out::println);

        return services;
    }

}
